﻿#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "keymng_msg.h"

//main344：keymng编解码测试
int main344()
{
	int ret = 0;
	Teacher t1;
	unsigned char* myout = NULL;
	int myOutlen;

	Teacher* myStruct = NULL;
	int iType = 0;

	memset(&t1, 0, sizeof(Teacher));
	strcpy(t1.name, "name1");
	t1.age = 100;
	t1.p = (char*)malloc(100);
	strcpy(t1.p, "aaaaabbbbb");
	t1.plen = strlen(t1.p);

	ret = MsgEncode(&t1, ID_MsgKey_Teacher, &myout, &myOutlen);
	if (ret != 0)
	{
		printf("func MsgEncode() err: %d\n", ret);
		return ret;
	}
	printf("-----------------------------MsgEncode finish\n");

	ret = MsgDecode(myout, myOutlen, &myStruct, &iType);
	if (ret != 0)
	{
		printf("func MsgDecode() err: %d\n", ret);
		return ret;
	}

	if (strcmp(t1.name, myStruct->name) == 0 && memcmp(t1.p, myStruct->p, myStruct->plen) == 0)
	{
		printf("编码 == 解码，success!\n");
	}
	else
	{
		printf("编码 != 解码，fail!\n");
	}

	//1.释放内存块；
	MsgMemFree((void**)&myout, 0);
	MsgMemFree((void**)&myStruct, iType);

	printf("hello...\n");

	return 0;
}